function toDecimal(binary) {
  let demical = 0;
  for (let i = 0; i < binary.length; i++) {
    demical += binary[i] * 2 ** (binary.length - i -1);
  }
  return demical;
}

let output = toDecimal('1010');
console.log(output)